-
Notifications
You must be signed in to change notification settings - Fork 40
Anotando colunas inicial e final para lexemas encontrados pelo Lexador. #1093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Anotando colunas inicial e final para lexemas encontrados pelo Lexador. #1093
Conversation
📊 Cobertura de Código
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds column tracking (colunaInicio and colunaFim) to lexer tokens, enabling editors to provide more precise code suggestions and improvements. The changes update the Simbolo class and interface to include starting and ending column positions for each token.
Changes:
- Added
colunaInicioandcolunaFimfields toSimboloInterfaceandSimboloclass - Updated all lexer implementations to calculate and store column positions when creating tokens
- Modified semantic analyzer to propagate column information to code suggestions
- Added comprehensive test coverage for column tracking functionality
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| fontes/interfaces/simbolo-interface.ts | Added optional colunaInicio and colunaFim fields to the symbol interface |
| fontes/lexador/simbolo.ts | Added colunaInicio and colunaFim properties and constructor parameters with default values |
| fontes/lexador/lexador.ts | Updated adicionarSimbolo to calculate and include column positions |
| fontes/lexador/lexador-base.ts | Updated adicionarSimbolo to calculate and include column positions |
| fontes/lexador/lexador-base-linha-unica.ts | Updated adicionarSimbolo to calculate and include column positions |
| fontes/lexador/micro-lexador.ts | Updated adicionarSimbolo to calculate and include column positions |
| fontes/lexador/micro-lexador-pitugues.ts | Updated adicionarSimbolo to calculate and include column positions |
| fontes/lexador/dialetos/lexador-tenda.ts | Updated adicionarSimbolo to calculate and include column positions |
| fontes/lexador/dialetos/lexador-prisma.ts | Updated adicionarSimbolo to calculate and include column positions |
| fontes/lexador/dialetos/lexador-portugol-ipt.ts | Updated adicionarSimbolo to calculate and include column positions |
| fontes/lexador/dialetos/lexador-pitugues.ts | Updated adicionarSimbolo to calculate and include column positions |
| fontes/lexador/dialetos/lexador-egua-classico.ts | Updated adicionarSimbolo to calculate and include column positions |
| fontes/lexador/dialetos/lexador-calango.ts | Updated adicionarSimbolo to calculate and include column positions |
| fontes/analisador-semantico/analisador-semantico.ts | Updated to use symbol column information in code suggestions |
| fontes/analisador-semantico/analisador-semantico-base.ts | Fixed import statement formatting |
| testes/lexador/lexador.test.ts | Added comprehensive tests for column tracking across various token types |
| testes/analisador-semantico/analisador-semantico.test.ts | Updated tests to verify column information in semantic suggestions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| adicionarSimbolo(tipo: string, literal: any = null): void { | ||
| const texto: string = this.codigo[this.linha].substring(this.inicioSimbolo, this.atual); | ||
| this.simbolos.push(new Simbolo(tipo, texto, literal, this.linha + 1, this.hashArquivo)); | ||
| const comprimento = Math.max(texto.length, 1); | ||
| const colunaInicio = this.inicioSimbolo + 1; | ||
| const colunaFim = this.inicioSimbolo + comprimento; | ||
| this.simbolos.push(new Simbolo(tipo, texto, literal, this.linha + 1, this.hashArquivo, colunaInicio, colunaFim)); |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The identificarPalavraChave method directly creates a Simbolo instance without calling adicionarSimbolo. This method bypasses the column tracking logic added here, meaning keyword tokens won't have proper colunaInicio and colunaFim values. Consider refactoring this method to use adicionarSimbolo or to manually calculate and include column information when creating the Simbolo instance.
| adicionarSimbolo(tipo: any, literal?: any): void { | ||
| const texto = this.codigo[this.linha].substring(this.inicioSimbolo, this.atual); | ||
| this.simbolos.push(new Simbolo(tipo, texto, literal, this.linha, -1)); | ||
| const comprimento = Math.max(texto.length, 1); | ||
| const colunaInicio = this.inicioSimbolo + 1; | ||
| const colunaFim = this.inicioSimbolo + comprimento; | ||
| this.simbolos.push(new Simbolo(tipo, texto, literal, this.linha, -1, colunaInicio, colunaFim)); |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lexer has methods (analisarTexto, analisarNumero, identificarPalavraChave) that directly create Simbolo instances without calling adicionarSimbolo. These methods bypass the column tracking logic added here, meaning text, number, and keyword tokens won't have proper colunaInicio and colunaFim values. Consider refactoring those methods to use adicionarSimbolo or to manually calculate and include column information when creating Simbolo instances.
| adicionarSimbolo(tipo: any, literal?: any): void { | ||
| const texto: string = this.codigo[this.linha].substring(this.inicioSimbolo, this.atual); | ||
| const lexema = literal || texto; | ||
| const comprimentoLexema = typeof lexema === 'string' ? lexema.length : 0; | ||
| const comprimento = Math.max(comprimentoLexema, texto.length) || 1; | ||
| const colunaInicio = this.inicioSimbolo + 1; | ||
| const colunaFim = this.inicioSimbolo + comprimento; | ||
| this.simbolos.push( | ||
| new Simbolo(tipo, literal || texto, literal, this.linha + 1, this.hashArquivo) | ||
| new Simbolo(tipo, lexema, literal, this.linha + 1, this.hashArquivo, colunaInicio, colunaFim) | ||
| ); |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lexer has methods (analisarTexto, analisarNumero, identificarPalavraChave) that directly create Simbolo instances without calling adicionarSimbolo. These methods bypass the column tracking logic added here, meaning text, number, and keyword tokens won't have proper colunaInicio and colunaFim values. Consider refactoring those methods to use adicionarSimbolo or to manually calculate and include column information when creating Simbolo instances.
| colunaInicio: declaracao.simbolo.colunaInicio, | ||
| colunaFim: declaracao.simbolo.colunaFim, |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the Simbolo class always provides colunaInicio and colunaFim values (defaulting to 0), the SimboloInterface declares them as optional. This creates a type mismatch when assigning these potentially undefined values to CorrecaoSugeridaInterface, which requires non-optional number values. Consider using the nullish coalescing operator to provide a fallback value: colunaInicio: declaracao.simbolo.colunaInicio ?? 0 and colunaFim: declaracao.simbolo.colunaFim ?? 0.
| colunaInicio: declaracao.simbolo.colunaInicio, | |
| colunaFim: declaracao.simbolo.colunaFim, | |
| colunaInicio: declaracao.simbolo.colunaInicio ?? 0, | |
| colunaFim: declaracao.simbolo.colunaFim ?? 0, |
| colunaInicio: number; | ||
| colunaFim: number; |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an inconsistency between the interface and implementation. The SimboloInterface defines colunaInicio and colunaFim as optional fields (with ?), but the Simbolo class implementation declares them as required (non-optional). While the constructor provides default values (0), this discrepancy could cause confusion. Consider making these fields optional in the class as well (colunaInicio?: number) to match the interface, or remove the optional marker from the interface if these fields should always be present.
| adicionarSimbolo(tipo: any, literal: any = null): void { | ||
| const texto: string = this.codigo[this.linha].substring(this.inicioSimbolo, this.atual); | ||
| this.simbolos.push(new Simbolo(tipo, texto, literal, this.linha + 1, this.hashArquivo)); | ||
| const comprimento = Math.max(texto.length, 1); | ||
| const colunaInicio = this.inicioSimbolo + 1; | ||
| const colunaFim = this.inicioSimbolo + comprimento; | ||
| this.simbolos.push(new Simbolo(tipo, texto, literal, this.linha + 1, this.hashArquivo, colunaInicio, colunaFim)); | ||
| } |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lexer has methods (analisarTexto, analisarNumero, identificarPalavraChave) that directly create Simbolo instances without calling adicionarSimbolo. These methods bypass the column tracking logic added here, meaning text, number, and keyword tokens won't have proper colunaInicio and colunaFim values. Consider refactoring those methods to use adicionarSimbolo or to manually calculate and include column information when creating Simbolo instances.
Com essa modificação será viável adicionar sugestões de melhorias do código para editores.